//
//  SubmitEvaluationVm.swift
//  Pods
//
//  Created by eme on 2017/4/5.
//
//

import UIKit
import RxSwift
import SwiftyJSON
import ModelProtocol
import NetWorkCore

class SubmitEvaluationVm{
    
    let submitevaluation = PublishSubject<String>()
    
    let backDate = PublishSubject<Bool>()
    
    let disposeBag = DisposeBag()
    
    let error = PublishSubject<MikerError>()
    
    let loading : Observable<Bool>
    
    
    init (){
        
        let requestIndicator = ActivityIndicator()
        self.loading = requestIndicator.asObservable()
        
        let request = submitevaluation.map{ evaluation in
            
            return MineApi.submitEvaluate(orderevaluate: evaluation)
            
            }.shareReplay(1)
        
        let response = request.emeRequestApiForJson(requestIndicator).shareReplay(1)
        
        response.subscribe(onNext:{[unowned self] result in
            
            switch result{
                
            case .success(_):
                
                self.backDate.onNext(true)
                
            case.failure(let error):
                
                self.error.onNext(error)
                
            }
            
        }).addDisposableTo(disposeBag)
    }
    
}
